﻿<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:editor="http://icsharpcode.net/sharpdevelop/avalonedit"
        xmlns:extension="clr-namespace:SqLiteEditor.Extension"
        xmlns:staticData="clr-namespace:SqLiteEditor.Helper"
        xmlns:avalonDock="http://avalondock.codeplex.com"
        xmlns:Forms="clr-namespace:SqLiteEditor.Forms" x:Class="SqLiteEditor.MainWindow"
        Title="SQLite Management 1.0" Height="600" Width="800" Icon="main.ico" Background="#FF2D3E5B" WindowState="Maximized">

    <Window.Resources>
        <ContextMenu x:Key="TabelContextMenu">
            <MenuItem x:Name = "mnu_Design" Header="Design" Command="{Binding Commands.cmdDesignTable}"/>
            <MenuItem x:Name = "mnu_Select" Header="Select Data" Command="{Binding Commands.cmdSelectTopn}"/>
            <MenuItem x:Name = "mnu_Edit"  Header="Edit Data" Command="{Binding Commands.cmdEditData}"/>
            <Separator/>
            <MenuItem x:Name = "mnu_Delete"  Header="Delete" Command="{Binding Commands.cmdDeleteTable}"/>
            <MenuItem x:Name = "mnu_Rename"  Header="Rename" Command="{Binding Commands.cmdRenameTable}"/>
            <Separator/>
            <MenuItem x:Name = "mnu_Refresh"  Header="Refresh"/>
        </ContextMenu>

        <ContextMenu x:Key="ViewContextMenu">
            <MenuItem x:Name = "mnu_View_Delete"  Header="Delete" Command="{Binding Commands.cmdDeleteView}"/>
            <MenuItem x:Name = "mnu_View_Rename"  Header="Rename" />
            <Separator/>
            <MenuItem x:Name = "mnu_View_Refresh"  Header="Refresh"/>
        </ContextMenu>

        <ContextMenu x:Key="IndexContextMenu">
            <MenuItem x:Name = "mnu_Index_Delete"  Header="Delete" Command="{Binding Commands.cmdDeleteIndex}"/>
            <MenuItem x:Name = "mnu_Index_Rename"  Header="Rename"  Command="{Binding Commands.cmdRenameIndex}"/>
            <Separator/>
            <MenuItem x:Name = "mnu_Index_Refresh"  Header="Refresh"/>
        </ContextMenu>

        <ContextMenu x:Key="TabelsContextMenu">
            <MenuItem Header="New Table..." Command="{Binding Commands.cmdNewTable}"/>
            <MenuItem Header="Refresh"/>
        </ContextMenu>

        <ContextMenu x:Key="ViewsContextMenu">
            <MenuItem Header="New View..." Command="{Binding Commands.cmdNewView}" />
            <MenuItem Header="Refresh"/>
        </ContextMenu>

        <ContextMenu x:Key="IndexsContextMenu">
            <MenuItem Header="New Index..." Command="{Binding Commands.cmdNewIndex}" />
            <MenuItem Header="Refresh"/>
        </ContextMenu>

        <staticData:DataTypeList x:Key="DataTypeList"/>
        <staticData:DataTypeBool x:Key="DataTypeBool"/>

    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Menu Height="22" Grid.Row="0" Grid.ColumnSpan="3" Background="#FFBCC7D8">
            <MenuItem Header="File">
                <MenuItem Header="Connect Object Explorer"  Command="{Binding Commands.cmdConnectDataBase}"/>
                <MenuItem Header="Disconnect Object Explorer" Command="{Binding Commands.cmdDisconnectDataBase}"/>
                <Separator/>
                <MenuItem Header="New DataBase"  Command="{Binding Commands.cmdCreateNewDataBase}"/>
                <MenuItem Header="Save As DataBase"/>
                <MenuItem Header="Close DataBase" Command="{Binding Commands.cmdDisconnectDataBase}"/>
                <Separator/>
                <MenuItem Header="Exit" Command="{Binding Commands.cmdExit}"/>
            </MenuItem>

            <MenuItem Header="Edit">
                <MenuItem  Command = "ApplicationCommands.Undo"/>
                <MenuItem  Command = "ApplicationCommands.Redo"/>
                <Separator/>
                <MenuItem Command = "ApplicationCommands.Cut"/>
                <MenuItem Command = "ApplicationCommands.Copy"/>
                <MenuItem Command = "ApplicationCommands.Paste"/>
                <MenuItem Command = "ApplicationCommands.Delete"/>
                <Separator/>
                <MenuItem Command = "ApplicationCommands.SelectAll"/>
                <Separator/>
                <MenuItem Header="Find and Replace"/>
            </MenuItem>
            <MenuItem Header="View">
                <MenuItem Header="Object Explorer" InputGestureText="F8" Command="{Binding Commands.cmdViewObjectWxplorer}" />
            </MenuItem>
            <MenuItem Header="Grid">
                <MenuItem Header =" FlowDirection" >
                    <MenuItem Header ="Left to Right" extension:MenuItemExtensions.GroupName="FlowDir" IsCheckable="True" Command="{Binding Commands.cmdLefttoRight}" />
                    <MenuItem Header ="Right to Left" extension:MenuItemExtensions.GroupName="FlowDir" IsCheckable="True" IsChecked="True"  Command="{Binding Commands.cmdRighttoLeft}" />
                </MenuItem>
                <MenuItem Header =" Font Size" x:Name="mnuFontSize" >
                    <MenuItem Header ="12 px" Tag="12" extension:MenuItemExtensions.GroupName="Fontsize" IsCheckable="True" Command="{Binding Commands.cmdFontSize}" />
                    <MenuItem Header ="14 px" Tag="14" extension:MenuItemExtensions.GroupName="Fontsize" IsCheckable="True" IsChecked="True" Command="{Binding Commands.cmdFontSize}" />
                    <MenuItem Header ="16 px" Tag="16" extension:MenuItemExtensions.GroupName="Fontsize" IsCheckable="True" Command="{Binding Commands.cmdFontSize}" />
                    <MenuItem Header ="18 px" Tag="18" extension:MenuItemExtensions.GroupName="Fontsize" IsCheckable="True" Command="{Binding Commands.cmdFontSize}" />
                    <MenuItem Header ="20 px" Tag="20" extension:MenuItemExtensions.GroupName="Fontsize" IsCheckable="True" Command="{Binding Commands.cmdFontSize}" />
                </MenuItem>
            </MenuItem>
            <MenuItem Header="Query"/>
            <MenuItem Header="Tools"/>
            <MenuItem Header="Window"/>
            <MenuItem Header="Help">
                <MenuItem Header="About" Command="{Binding Commands.cmdShowAbout}"/>
            </MenuItem>
        </Menu>

        <ToolBar Height="Auto" VerticalAlignment="Top" Grid.Row="1" Grid.ColumnSpan="3" Background="#FFBCC7D8" >

            <Separator Background="#FF8591A2"/>
            <Button Width="30" Height="30" Command="{Binding Commands.cmdNewQuery}" ToolTip="New Query">
                <Image Source="Resources/DataToolBar/New.ico" IsHitTestVisible="False" />
            </Button>

            <Button Width="30" Height="30" ToolTip="Save"  Command="{Binding Commands.cmdSaveChanges}" >
                <Image Source="Resources/DataToolBar/Save.ico" IsHitTestVisible="False"/>
            </Button>

            <Button Width="30" Height="30" x:Name="bConnectdb" Command="{Binding Commands.cmdConnectDataBase}" ToolTip="Connect">
                <Image Source="Resources/DataToolBar/connect1.png" IsHitTestVisible="False"/>
            </Button>


            <Button Width="30" Height="30" Command="{Binding Commands.cmdDisconnectDataBase}" ToolTip="Disconnect">
                <Image Source="Resources/DataToolBar/connect2.png" IsHitTestVisible="False"/>
            </Button>
            <Separator Background="#FF8591A2"/>
            <Button x:Name="btnExecuteQuery" Width="30" Height="30"  Command="{Binding Commands.ExecuteQuery}" ToolTip="Run">
                <Image Source="Resources/DataToolBar/Run.png" Width="16" Height="16" IsHitTestVisible="False"/>
            </Button>
        </ToolBar>

        <avalonDock:DockingManager Grid.Row="2"  x:Name="dockManager"  AllowMixedOrientation="True"   DocumentClosing="dockManager_DocumentClosing">
            <!--<avalonDock:DockingManager.Theme>-->
            <!--<avalonDock:VS2010Theme/>-->
            <!--</avalonDock:DockingManager.Theme>-->
            <avalonDock:LayoutRoot>

                <avalonDock:LayoutPanel Orientation="Horizontal">
                    <avalonDock:LayoutAnchorablePane DockWidth="250" >
                        <avalonDock:LayoutAnchorable   x:Name="avalonObjectExplorer"  Title="Object Explorer" ContentId="avalonObjectExplorer" PropertyChanged="avalonObjectExplorer_PropertyChanged" CanHide="False" CanClose="False">
                            <Grid  HorizontalAlignment="Left" VerticalAlignment="Stretch" Width="300" MinWidth="300" >

                                <Grid.RowDefinitions>
                                    <RowDefinition Height="30" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>

                                <ToolBar Grid.Row="0">
                                    <Button Width="20" Height="20" Margin="10,0,0,0" ToolTip="Connect"  Command="{Binding Commands.cmdConnectDataBase}">
                                        <Image Source="Resources/DataToolBar/s_connect.png" IsHitTestVisible="False"/>
                                    </Button>

                                    <Button Width="20" Height="20" Margin="2,0,0,0" ToolTip="Disconnect" Command="{Binding Commands.cmdDisconnectDataBase}">
                                        <Image Source="Resources/DataToolBar/s_disconect.png" IsHitTestVisible="False"/>
                                    </Button>
                                    <Separator/>
                                    <Button Width="20" Height="20" Margin="6,0,0,0" ToolTip="Refresh" Command="{Binding Commands.cmdRefreshTree}">
                                        <Image Source="Resources/DataToolBar/s_refresh.png" IsHitTestVisible="False"/>
                                    </Button>
                                </ToolBar>

                                <TreeView HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="MainTree" Grid.Row="1" DataContext="{Binding DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" >
                                    <!-- a custom root node for the tree -->
                                    <TreeViewItem x:Name="PART_TreeRoot" >
                                        <TreeViewItem.Header>
                                            <StackPanel Orientation="Horizontal" Margin="0,2,0,2" MaxWidth="200">
                                                <Image Source="Resources/DataToolBar/database.png" Width="16" Height="16" />
                                                <TextBlock x:Name="txtblock" Margin="2,0,0,0" VerticalAlignment="Center" FontWeight="Bold" Text="{Binding DBFileName}" />
                                            </StackPanel>
                                        </TreeViewItem.Header>

                                        <TreeViewItem x:Name="PART_Tabels" ContextMenu="{StaticResource TabelsContextMenu}" >
                                            <TreeViewItem.Header>
                                                <StackPanel Orientation="Horizontal" Margin="0,2,0,2">
                                                    <Image Source="Resources/DataToolBar/table_multiple.png" Width="16" Height="16" />
                                                    <TextBlock Margin="2,0,0,0" VerticalAlignment="Center" FontWeight="Bold" Text="{Binding TabelsLabel}" />
                                                </StackPanel>
                                            </TreeViewItem.Header>

                                        </TreeViewItem>

                                        <TreeViewItem x:Name="PART_Views" ContextMenu="{StaticResource ViewsContextMenu}" >
                                            <TreeViewItem.Header>
                                                <StackPanel Orientation="Horizontal" Margin="0,2,0,2">
                                                    <Image Source="Resources/DataToolBar/views.png" Width="16" Height="16" />
                                                    <TextBlock Margin="2,0,0,0" VerticalAlignment="Center" FontWeight="Bold" Text="{Binding ViewsLabel}" />
                                                </StackPanel>
                                            </TreeViewItem.Header>
                                        </TreeViewItem>

                                        <TreeViewItem x:Name="PART_Indexes" ContextMenu="{StaticResource IndexsContextMenu}">
                                            <TreeViewItem.Header>
                                                <StackPanel Orientation="Horizontal" Margin="0,2,0,2">
                                                    <Image Source="Resources/DataToolBar/Indexes.png" Width="16" Height="16" />
                                                    <TextBlock Margin="2,0,0,0" VerticalAlignment="Center" FontWeight="Bold" Text="{Binding IndexesLabel}" />
                                                </StackPanel>
                                            </TreeViewItem.Header>
                                        </TreeViewItem>

                                        <TreeViewItem x:Name="PART_Triggers" >
                                            <TreeViewItem.Header>
                                                <StackPanel Orientation="Horizontal" Margin="0,2,0,2">
                                                    <Image Source="Resources/DataToolBar/Triggers.png" Width="16" Height="16" />
                                                    <TextBlock Margin="2,0,0,0" VerticalAlignment="Center" FontWeight="Bold" Text="{Binding TriggersLabel}" />
                                                </StackPanel>
                                            </TreeViewItem.Header>
                                        </TreeViewItem>

                                    </TreeViewItem>

                                </TreeView>
                            </Grid>
                        </avalonDock:LayoutAnchorable>
                    </avalonDock:LayoutAnchorablePane>

                    <avalonDock:LayoutDocumentPaneGroup>
                        <avalonDock:LayoutDocumentPane>
                            <!--<avalonDock:LayoutDocument ContentId="document1" Title="Document 1" >
                                <StackPanel >
                                    
                                </StackPanel>
                            </avalonDock:LayoutDocument>-->

                        </avalonDock:LayoutDocumentPane>
                    </avalonDock:LayoutDocumentPaneGroup>
                    
                </avalonDock:LayoutPanel>

            </avalonDock:LayoutRoot>
        </avalonDock:DockingManager>

        <StatusBar Grid.Row="4" Grid.RowSpan="1" VerticalAlignment="Bottom" Margin="0" Grid.ColumnSpan="3" Height="25" Background="Khaki">
            <TextBlock Width="Auto" x:Name="tb_Version" Text="SQLite : "/>
            <Separator Background="#FFbdbdbd" Width="2"/>
            <TextBlock  Width="200"/>
            <Separator Background="#FFbdbdbd" Width="2"/>
            <TextBlock  Width="Auto" MinWidth="100" Text="{Binding NumSelectedRow}"/>
            <Separator Background="#FFbdbdbd" Width="2"/>
            <TextBlock  Width="Auto" MinWidth="100" Text="{Binding QueryTime}"/>
            <Separator Background="#FFbdbdbd" Width="2"/>
            <TextBlock  Width="Auto" MinWidth="100" Text="{Binding StatusMessage}"/>
        </StatusBar>
    </Grid>
</Window>
